
/*
 *
 * All Rights Reserved.
 */
package com.model.demo.designmodel.proxy.dbroute;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * OrderServiceStaticProxy
 *
 * @author Liao Dongshan, 2019年06月04日
 *
 */
public class OrderServiceStaticProxy implements OrderService {
    private OrderService orderService;

    private SimpleDateFormat sdf=new SimpleDateFormat("yyyy");

    public OrderServiceStaticProxy(OrderService orderService){
        this.orderService=orderService;
    }

    @Override
    public int saveOrder(Order order) {
        Date createTime = order.getCreateTime();
        Integer year=Integer.parseInt(sdf.format(createTime));
        System.out.println("【DB_"+year+"】数据源处理");
        DynamicDataSourceEntity.set(year);
        DynamicDataSourceEntity.restore();
        this.orderService.saveOrder(order);
        return 1;
    }
}
